package day05;

import java.util.LinkedList;
import java.util.Queue;

/**
 *代码随想录 用队列实现栈
 */
public class MyStack<T> {
    Queue<T> queue;
    public MyStack(){
        queue = new LinkedList<>();
    }

    public void push(T x){
        queue.offer(x);
        int size = queue.size();
        while (size-- > 1) {
            queue.offer(queue.poll());
        }
    }

    public T pop() {
        return queue.poll();
    }

    public T top() {
        return queue.peek();
    }

    public boolean isEmpty() {
        return queue.isEmpty();
    }
}
